<?php

/*
 *------------------------------------------------------------------------------
 * Project Name  : e-Synergy Library System
 *         Code  : ESN-LBS
 *
 * Created By    : Junlapong
 *         Date  : 2010/03/17
 *
 * $Id$
 *------------------------------------------------------------------------------
 *    copyright: e-Synergy Co., Ltd.
 *==============================================================================
 */

class Login_Model extends MY_Model
{
	function Login_Model() 
	{
		parent::MY_Model();

	}
	
	function getUser($username)
	{
		$SQL = " SELECT username
		              , password
		              , firstname
		              , authen_mode
		              , admin_flag
		           FROM s_user
		          WHERE username = ? 
		            AND enable_flag = 1
		            AND eff_date <= CURRENT_TIMESTAMP
		            AND exp_date  > CURRENT_TIMESTAMP ";
		
		$query  = $this->db->query($SQL, array($username));
		$result = $query->result();
		
		if (count($result) != 1)
		{
			return NULL;
		}
		else
		{
			list($result) = $result; // cast result array to object
			 
			$user = new User_Entity();			
			$user->username     = $result->username;
			$user->password     = $result->password;
			$user->display_name = $result->firstname;
			$user->authen_mode  = $result->authen_mode;
			$user->is_admin     = ($result->admin_flag === 1);
			
			return $user;
		}
	}
}

// END Login_Model class

/* End of file Login_Model */
/* Location: application/models/login_model.php */